package com.atguigu.c_generic_method;

import com.atguigu.a_test.Student;

import java.util.Date;

public class Demo {
    public static void main(String[] args) {
        show(new Student("张三",18));

        show(new Date());
    }

    public static <T> void show(T t){
        //代表此方法内多了一种 T 类型 , 仅供方法内使用
        System.out.println("t = " + t);

        //一定要做类型校验
        if (t instanceof Student){
            Student student = (Student) t;
            System.out.println("student.getName() = " + student.getName());
            return;
        }

        if (t instanceof Date){
            Date date = (Date) t;
            System.out.println("date.toLocaleString() = " + date.toLocaleString());
        }
    }
}
